package com.liry.security.repository.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liry.security.domain.entity.Role;
import com.liry.security.domain.po.RolePermission;
import java.util.Collection;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 角色表(Role)持久层mapper
 *
 * @author ALI
 * @since 2023-05-29 21:53:07
 */
public interface RoleMapper extends BaseMapper<Role> {

    @Select({
        "<script>",
        "select a.id as role_id,a.name as role_name,a.code as role_code,b.name as permission_name,b.code as permission_code from sys_role a left join sys_permission b on a.id = b.role_id",
        "where a.id in ",
        "<foreach collection='roleIds' item='id' index='index' open='(' close=')' separator='or'> " ,
        "#{id}</foreach>",
        "</script>"
    })
    List<RolePermission> selectByRoleIds(Collection<Integer> roleIds);

    @Select("select a.id as role_id,a.name as role_name,a.code as role_code,b.name as permission_name,b.code as permission_code,b.id as permission_id , b.parent_id as parent_permission_id,b.url as permission_url "
        + "from sys_role a inner join sys_permission b on a.id = b.role_id where a.deleted = 0")
    List<RolePermission> roleList();

}

